/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eleric.rememome.db.factory.impl;

import com.eleric.rememome.db.DbRetriever;
import com.eleric.rememome.db.MemoDbAdaptor;
import com.eleric.rememome.db.factory.DbRetrieverFactory;
import com.eleric.rememome.db.impl.DbMemoRetrieverVer2;
import com.eleric.rememome.memo.Memo;
import com.eleric.rememome.memo.impl.MemoVer2;

/**
 *
 * @author MWaldman
 */
public class MemoDbRetrieverFactory implements DbRetrieverFactory<Memo>
{

    public static final String KEY_ROWID = "_id";
    public static final String KEY_MEMO = "memo";
    public static final String KEY_CAT = "category";
    public static final String KEY_STATUS = "status";
    public static final String KEY_CREATION_TIME = "creationTimestamp";
    public static final String KEY_STATUS_TIME = "statusTimestamp";
    public static final String KEY_PRIORITY = "priority";
    public static final String[] COLUMNS =
    {
        KEY_ROWID,
        KEY_MEMO,
        KEY_CAT,
        KEY_STATUS,
        KEY_CREATION_TIME,
        KEY_STATUS_TIME,
        KEY_PRIORITY
    };
    private String table;
    private String prevTable;
    private MemoCategoryDbRetrieverFactory categoryFactory;

    public MemoDbRetrieverFactory(MemoDbAdaptor memoDbAdaptor)
    {
        this.table = memoDbAdaptor.getMemoTableName();
        this.prevTable = memoDbAdaptor.getMemoTableName()+memoDbAdaptor.getPreviousVersion();
        this.categoryFactory = new MemoCategoryDbRetrieverFactory(memoDbAdaptor);
    }

    public DbRetriever<Memo> getCurrentVersionDbRetriever()
    {
        return new DbMemoRetrieverVer2(table, categoryFactory.getCurrentVersionDbRetriever());
    }

    public DbRetriever<Memo> getPreviousVersionDbRetriever()
    {
        // No previous version of this table
        return new DbMemoRetrieverVer2(prevTable, categoryFactory.getPreviousVersionDbRetriever());
//        return new DbMemoRetrieverVer1(table, categoryFactory.getPreviousVersionDbRetriever());
    }

    public Memo getInstance()
    {
        return new MemoVer2();
    }
}
